<?php

if(!defined('IN_SYS')) exit('Access Denied');

class flink_controller extends admincp{

	public function __construct(){
		parent::__construct();
	}

	public function index(){
		$where = "";
		$sitename = gp("sitename");
		if($this->currentYumingId){
			$where .= (empty($where) ? " where " : " and ")." (yuming_id=0 or yuming_id='$this->currentYumingId') ";
		}
		if($sitename){
			$where .= (empty($where) ? " where " : " and ")." sitename like '%$sitename%'";
		}

		$pg = new page("select * from flink {$where} order by id desc");

		$list = $pg->get_list(20);
		$page = $pg->get_page();
		require self::tpl('flink');
	}

	public function add(){
		if(IS_POST){
			$time = time();
			$v = gp("data");
			db::query("INSERT into flink (sitename,url,note,addtime,status,yuming_id) 
				values ('$v[sitename]', '$v[url]', '$v[note]','$time','$v[status]','$v[yuming_id]') ");
			self::json( array('status' => 1, 'msg' => '添加成功', 'redirect' => '?m=flink&yuming_id='.$v['yuming_id']) );
		}else{
			require self::tpl("flink_add");
		}
	}
	
	public function edit(){
		$id = gp('id');
		if(IS_POST){
			$v = gp("data");
			db::query("update flink set sitename='$v[sitename]', url='$v[url]', note='$v[note]' ,status='$v[status]',yuming_id='$v[yuming_id]'
				where id='$id' ");
			self::json( array('status' => 1, 'msg' => '修改成功', 'redirect' => '?m=flink&yuming_id='.$v['yuming_id']) );
		}else{
			$r = db::find("select *  from flink  where id='$id' ");
			require self::tpl("flink_edit");
		}
	}

	public function del(){
		$yuming_id=gp("yuming_id");
		$id = gp('id');
		db::query("delete from flink where id='$id' ");
		self::redirect('?m=flink&yuming_id='.$yuming_id, "删除成功");
	}

}


